<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
<meta http-equiv="Expires" CONTENT="-1">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">
<link rel="stylesheet" href="{:C('VSHOP_CSS')}log.css"/>
<script src="{:C('VSHOP_JS')}jquery-1.9.1.min.js"></script>
<script src="{:C('VSHOP_JS')}home.js"></script>
</head>
<body>
<header>
  <div class="head"><a href="javascript:history.go(-1)" class="head-return"></a>
    <h2 class="head-title">注册</h2>
  </div>
</header>
<main>
  <div class="blank10"></div>
  <div class="log-box">
         <form action="" method="post" id="register">
    <ul>
      <li><em>用户名</em>
        <input name="username" type="text" class="txt" placeholder="" id="username">
      </li>
      <li><em>登录密码</em>
        <input name="password" type="text" class="txt" placeholder="请输入新密码" id="password">
      </li>
      <li><em>确认密码</em>
        <input name="twopass" type="text" class="txt" placeholder="请确认新密码" id="twopass">
      </li>
      <li class="bod-none">
      </li>
      <input type="hidden" name="pid"  value="{$_GET['pid']}">
     <input class="btn-red" type="submit" value="注册"  /> 

    </ul>
     </form>
  </div>
</main>
<div class="blank10"></div>

<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
<link rel="stylesheet" href="{:C('VSHOP_JS')}validator/jquery.validator.css"/>
<script type="text/javascript">

    $('#register').validate({
          rules:{
                  username:{
                    required:true,
                    minlength: 2
                  },
                  password:{
                    required:true,
                    minlength: 6
                  },
                  twopass:{
                    required:true,
                    minlength: 5,
                    equalTo: "#password"
                  }
                },
                messages: {
                  username:{
                    required:'请填写用户名',
                    minlength: jQuery.format("密码不能小于2个字符")
                  },
                  password: {
                      required: "请填写密码",
                      minlength: jQuery.format("密码不能小于6个字符")
                  },
                  twopass: {
                      required: "请填写确认密码",
                      minlength: "密码不能小于6个字符",
                      equalTo: "两次输入密码不一致"
                  }
                },
                submitHandler: function(form) {
                  // do other things for a valid form
                  var $uname=$("input[name='username']").val();
                  var $pass=$("input[name='password']").val();
                  var $pid=$("input[name='pid']").val();
                  $.ajax({
                    url:'/vshop.php/Home/Login/saveUser',
                    type:'post',
                    dataType:'json',
                    data:{'uname':$uname,'pass':$pass,'pid':$pid},
                    success:function(message){
                       //var message=jQuery.parseJSON(message);
                       switch(message.status){
                          case 1:
                            window.location.href="/vshop.php/Home/User/index"
                          break;
                          case 0:
                          case 2:
                          alert(message.msg);
                          window.location.reload();
                          break;
                       }

                    }
                  })
                  return false;
                }
      
          })
  
  
</script>

</body>
</html>
